package sctu.edu.java.year2016.team04.luoxinghua.projectprouact;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

/**
 * Created by 落叶的思恋 on 2016/6/27.
 */
public class lianix {

        public static void  main(String[] args) {

            String url="jdbc:mysql://10.131.31.168/wulixia";
            String userName = "root";
            String password = "wlx989796";
            Connection con = null;
            try {

                Class.forName("com.mysql.jdbc.Driver");
            } catch (Exception e) {

                System.out.println("加载驱动器类时出现异常");
            }
            try {

                //获取数据库连接
                con = DriverManager.getConnection(url, userName, password);
            } catch (Exception e) {
               e.getMessage();
                System.out.println("出现SQLException异常");
            }
            System.out.println("加载驱动器成功");
            //操作MySql数据库
            try {
                PreparedStatement preStatement = con.prepareStatement("insert into userinfo values(?,?,?)");
                preStatement.setString(1, "TestString1");
                preStatement.setString(2, "TestString2");
                preStatement.setDate(3, new java.sql.Date((new java.util.Date()).getTime()));
                preStatement.executeUpdate();
                preStatement.close();
                con.close();
                System.out.println("写入MySQL数据库成功");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


}
